<?php
/**
 * 用户Model
 * @author zhangbaochao
 *
 */
class UserModel extends Model{
	protected	$tableName	=	'user';
    var $uid;
    
	/**
	 * 添加用户信息
	 * @param array $data
	 * @return array
	 */
	public function addUser($data){
		return $this->add($data);
	}
    
    /**
     * 根据用户名密码查询用户
     * @param string $username
     * array
     */
    public function findUserByUsernamePassword($username,$password){
    	$map[username] = array('gt',$username);
    	$map[password] = array('gt',$password);
    	return $this->where($map)->select();
    }
    
    /**
     * 根据用户ID查询用户
     * @param unknown_type $uid
     * @return array
     */
    public function findUserByUid($uid){
    	return $this->find($uid);
    }
    
    /**
     * 更新用户信息
     * @param array $map
     */
    public function updateUser($data = array()){
    	M('user')->data($data)->save();
    }
    
	/**
     * 删除用户
     * 
     * @param array|string $uids
     * @return boolean
     */
    public function deleteUser($uids) {
    	//防误操作
    	$uids = is_array($uids) ? $uids : explode(',', $uids);
    	foreach($uids as $k => $v) {
    		if ( !is_numeric($v) ) unset($uids[$k]);
    	}
    	if ( empty($uids) ) return false;
    	
    	$map['uid'] = array('in', $uids);
    	//user
    	M('user')->where($map)->delete();
    	return true;
    }
}

?>